package com.example.mybatisplusdemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mybatisplusdemo.model.domain.Booking;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yrd
 * @since 2025-07-07
 */
public interface BookingMapper extends BaseMapper<Booking> {

    /**
     * 获取用户预订信息并关联航班信息
     * 
     * @param userId 用户ID
     * @return 用户预订列表，包含航班信息
     */
    @Select("SELECT " +
            "b.id, " +
            "b.user_id, " +
            "b.flight_id, " +
            "b.booking_time, " +
            "b.status, " +
            "b.price, " +
            "b.currency, " +
            "b.supplier, " +
            "b.supplier_reference, " +
            "f.flight_number, " +
            "f.departure_airport_code as departureAirport, " +
            "f.arrival_airport_code as arrivalAirport, " +
            "f.departure_time as departureTime, " +
            "f.arrival_time as arrivalTime, " +
            "f.airline_code, " +
            "f.duration, " +
            "f.service_class " +
            "FROM booking b " +
            "LEFT JOIN flight f ON b.flight_id = f.id " +
            "WHERE b.user_id = #{userId} " +
            "ORDER BY b.booking_time DESC")
    List<Map<String, Object>> getUserBookingsWithFlightInfo(@Param("userId") Long userId);

}
